#include <iostream>
#include "Thread.hpp"

// 单线程测试案例
int main()
{
    ThreadModule::Thread t([]()
                           { std::cout << "Hello World" << std::endl; });
    t.Start();
    std::cout << t.Name() << "is running" << std::endl;
    sleep(1);
    t.Stop();
    std::cout << t.Name() << "stop" << std::endl;
    bool n = t.Join();
    if (n)
    {
        std::cout << t.Name() << "等待成功" << std::endl;
    }
    else
    {
        std::cout << t.Name() << "等待失败" << std::endl;
    }

    sleep(5);
    ThreadModule::Thread t1([]()
                            {
        while(true)
        {
        std::cout<<"Hello World"<<std::endl;
        sleep(1);
        } });
    t1.Start();
    std::cout << t1.Name() << "is running" << std::endl;
    // t1线程分离
    t1.Detach();
    sleep(1);
    bool n1 = t1.Join();
    if (n1)
    {
        std::cout << t1.Name() << "等待成功" << std::endl;
    }
    else
    {
        std::cout << t1.Name() << "等待失败" << std::endl;
    }
    sleep(5);
    return 0;
}